/*
clsquare - closed loop simulation system
Copyright (c) 2004, Neuroinformatics Group, Prof. Dr. Martin Riedmiller,
University of Osnabrueck

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.
   * Neither the name of the <ORGANIZATION> nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. 
*/

#ifndef _DEFAULTCONTROL_H_
#define _DEFAULTCONTROL_H_

#include "controller.h"
   
/** Base class for all controllers in CLSquare.*/
class DefaultControl: public Controller {
 public:
  /** Computes an action, given an observation of a state .
   * \param observation: observation of current state
   * \param action: action to execute in current state.
   * \return true, for success. */ 
  virtual bool get_action(const double* observation, double* action);
  
  /** Initializes controller.
   * \param observation_dim: dimension of observation space
   * \param action_dim: dimension of action space. 
   * \param deltat: duration of one control cycle [s]
   * \param fname: file, which contains configuration of controller
   * \param chapter: chapter in which the configuration is located
   * \return true, for success. */
  virtual bool init(const int observation_dim, const int action_dim, double deltat, const char* fname=0, const char* chapter=0);
  
  /** Terminating control. 
   * \return true for success. */
  virtual bool deinit();

  /** Notifies that the environment has given a reward for the last state transition.
   * \param reward: reward given by the plant */
  virtual void notify_reward(const double reward) {return;};
  
  /** Notifies that an epsiode has started. 
   * \param initial_observation: observation of initial state */
  virtual void notify_episode_starts(const double* initial_observation) { notify_episode_starts();};
  
  /** Notifies that an episode has started. */
  virtual void notify_episode_starts();
  
  /** Notifies that an episode has stopped. 
   * \param final_observation: observation of final state
   * \param final_reward: reward for terminal state
   * \param is_terminal_state: true, if final state is a terminal state */
  virtual void notify_episode_stops(const double* final_observation, double final_reward, bool is_terminal_state){notify_episode_stops();};
  
  /** Notifies that an episode has stopped. */
  virtual void notify_episode_stops();

  virtual ~DefaultControl(){return;};
  
 protected:
  int      observation_dim;
  int      action_dim;
  double   delta_t;
  
  int      verbosity;
  double*  fixed_action;

  bool read_options(const char* fname , const char* chapter);
};

#endif
